import { _decorator, CCObject, Component, Director, physics, PhysicsSystem2D, v2, Vec2, EPhysics2DDrawFlags } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('EnablePhy')
export class EnablePhy extends Component {
    private _gravity: Vec2 = v2(0, -0); // 引擎默认重力
    private _is_debug: boolean = true; // 是否打开调试区域

    protected onLoad(): void {
        PhysicsSystem2D.instance.enable = true; // 开启物理引擎
        PhysicsSystem2D.instance.gravity = this._gravity; // 设置重力

        if (this._is_debug) {
            PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
                                                        EPhysics2DDrawFlags.Pair |
                                                        EPhysics2DDrawFlags.CenterOfMass |
                                                        EPhysics2DDrawFlags.Joint
                                                        EPhysics2DDrawFlags.Shape;
          } else PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.None;
    }

}
